package com.ericom.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
public class Country extends BaseObject {
    @Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id).append("code", code)
				.append("name", name).append("provinces", provinces).toString();
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof Country))
			return false;
		Country castOther = (Country) other;
		return new EqualsBuilder().append(code, castOther.code)
				.append(name, castOther.name)
				.append(provinces, castOther.provinces).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(code).append(name)
				.append(provinces).toHashCode();
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}


	private Long id;
    private String code;    
    private String name;
    
    private Set<Province> provinces=new HashSet<Province>();
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
    @OneToMany(mappedBy="country",cascade=CascadeType.ALL,fetch=FetchType.LAZY,targetEntity=Province.class)
	public Set<Province> getProvinces() {
		return provinces;
	}
	

	public void setProvinces(Set<Province> provinces) {
		this.provinces = provinces;
	}

}
